﻿
@{
    ViewBag.Title = "BindUser";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    
    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Scripts/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
    <title>会员等级管理</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div>
        <script type="text/html" id="barDemo">
            <div class="layui-btn-container">
                <button type="button" lay-event="add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe654;新增</i></button>
                <button type="button" lay-event="update" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe642;修改</i></button>
                <button type="button" lay-event="delete" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe640;删除</i></button>
            </div>
            </script>
            <div class="layui-form-item">
                <label class="layui-form-label">登录名：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="UserName">
                </div>
                <label class="layui-form-label">真实姓名：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="RealName">
                </div>
                <label class="layui-form-label">联系电话：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="Tell">
                </div>
                <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;搜索</i></button>
            </div>
            <table class="layui-inline" lay-filter="table" id="cardList"></table>
    </div>
    @*行内工具栏*@
    @*<script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>*@
    <script>

        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;
            //载入表格
            table.render({
                elem: '#cardList',
                url: "/User/BindUser",
                toolbar: '#barDemo',
                 defaultToolbar: ['filter', 'print', 'exports'],
                method: "post",
                //开启分页
                page: 'true',
                cols: [
                    [{
                        type: 'checkbox'
                    }, {
                        field: 'U_ID',
                        width: 150,
                        title: '用户编号',
                        sort: true
                    },
                    {
                        field: 'U_LoginName',
                        width: 150,
                        title: '登录名',
                        sort: true
                    },
                    {
                        field: 'U_RealName',
                        width: 150,
                        title: '真实姓名',

                    },
                    {
                        field: 'U_Sex',
                        width: 150,
                        title: '性别'
                      },
                    {
                        field: 'U_Telephone',
                        width: 150,
                        title: '联系电话'
                    },
                    {
                        field: 'U_Role',
                        width: 150,
                        title: '角色'
                    },
                    {
                        field: 'U_CanDelete',
                        width: 150,
                        title: '是否可以删除',
                    }
                    ]
                ]
            });

            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var UserName = $('#UserName').val();
                var RealName = $('#RealName').val();
                var Tell = $('#Tell').val();
                //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        'U_LoginName': UserName,
                        'U_RealName': RealName,
                        'U_Telephone': Tell
                    }
                });
            })

           
            table.on('toolbar(table)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id).data;
              switch(obj.event){
                case 'add':
                layer.open({
                    type: 2,
                    content: ['/User/UserInsert', 'no'],
                    area: ['500px', '500px'],
                    offset: ['100px', '400px'],
                    skin: 'layui-layer-molv',
                    maxmin: true,
                    id: 'add',
                    end: function () { table.reload('cardList') }
                });
                break;
                  case 'delete':
                 if (checkStatus[0] != null) {
                            var U_ID = checkStatus[0].U_ID;
                            layer.confirm('您确定要删除id为' + U_ID + "的会员吗", function (index) {
                                $.ajax({
                                    type: "post",
                                    url: "/User/UserDele",
                                    data: { U_ID: U_ID },
                                    success: function (data) {
                                        if (data.code == 0) {
                                            parent.layer.msg(data.msg, { icon: 1 });
                                            table.reload('cardList');
                                            obj.config.U_ID.del();
                                        } else {
                                            parent.layer.msg(data.msg, { icon: 5 });
                                        }
                                    }
                                })
                                layer.close(index);
                            });
                        } else {
                            layer.msg("请选择一行数据", { icon: 7 });
                        }
                    
                break;
                  case 'update':
                      if (checkStatus[0] != null) {
                          var U_ID = checkStatus[0].U_ID;
                                layer.open({
                                    type: 2,
                                    content: ['/User/UserUpda/' + U_ID + '', 'no'],
                                    area: ['500px', '600px'],
                                    offset: ['100px', '400px'],
                                    skin: 'layui-layer-molv',
                                    maxmin: true,
                                    //弹窗关闭刷新列表
                                    end: function () { table.reload('cardList') }
                                });

                        } else {
                               layer.msg("请选择一行数据", { icon: 7 });
                        }
                break;
              };
            });
           

        })



    </script>
</body>
</html>


